package cn.zwx.base.entity;

import cn.zwx.base.enums.ResponseCodeEnum;
import lombok.Data;

import java.io.Serializable;

/**
 * @author zhangwenxue
 */
@Data
public class ResponseEntity<T> implements Serializable {

    private int code;

    private String msg ;

    private T data;

    private boolean status;

    private ResponseEntity() {
        // 设置初始值
        this.code = ResponseCodeEnum.SUCCESS.getCode();
        this.msg = ResponseCodeEnum.SUCCESS.getMsg();
    }

    public static <T> ResponseEntity<T> success() {
        return success(null);
    }

    public static <T> ResponseEntity<T> success(T data) {
        return success(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(), data);
    }


    public static <T> ResponseEntity<T> success(int code, String msg, T data) {
        ResponseEntity<T> responseEntity = new ResponseEntity<T>();
        responseEntity.setCode(code);
        responseEntity.setMsg(msg);
        responseEntity.setData(data);
        responseEntity.setStatus(Boolean.TRUE);
        return responseEntity;
    }

    public static <T> ResponseEntity<T> fail(int code, String msg) {
        ResponseEntity<T> responseEntity = new ResponseEntity<T>();
        responseEntity.setCode(code);
        responseEntity.setMsg(msg);
        responseEntity.setStatus(Boolean.FALSE);
        return responseEntity;
    }
    public static <T> ResponseEntity<T> fail(ResponseCodeEnum responseCodeEnum) {
        ResponseEntity<T> responseEntity = new ResponseEntity<T>();
        responseEntity.setCode(responseCodeEnum.getCode());
        responseEntity.setMsg(responseCodeEnum.getMsg());
        responseEntity.setStatus(Boolean.FALSE);
        return responseEntity;
    }



}
